home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
emulation
/
c64gfx
/
man
/
bfli.txt
< prev
next >
Wrap
Text File
|
1999-05-14
|
16KB
|
421 lines
--------------------------------------------------------------------------
In This Issue: BFLI - New graphics modes 2
FLI gave us more color to the screen, AFLI increased the horizontal
resolution and partly the color selection by using the hires mode.
BFLI stands for 'Big FLI' and gives us 400 lines instead of the
usual two hundred. AFLI and BFLI can be combined, but we are not
going into that (yet ?).
Pasi 'Albert' Ojala albert@cs.tut.fi
--------------------------------------------------------------------------
BFLI - New graphics modes 2
---------------------------
One day I was watching some demos that used linecrunch routines for
whole-screen multicolor-graphics upscrollers. I already had my
theories about how and why linecrunch worked, but because I had not
used it anywhere, the details were a bit vague. In fact, I have
many times accidentally created linecrunch effects when trying to do
something else with $D011. Probably every demo coder has.
But you learn by doing. I had the idea of using linecrunch for FLI
instead of a simple multicolor picture as it always seemed to be
used. However, this has probably been done before and because I
don't like to do things that have been done before, I decided to use
linecrunch to show a two-screen-tall FLI picture.
_Linecrunch Basics_
For those not familiar with linecrunch routines: linecrunch is used
to scroll the screen UPWARDS by convincing VIC-II that it has
already showed more character rows than it in reality has shown.
Surprisingly (or then, maybe not :) this consists of fiddling with
$D011. The timing is critical as always.
Linecrunch works by setting $D011 equal the line before the current
line and VIC-II will happily think that it is time to move on to the
next character row - add 40 to the video matrix counter, 320 to the
graphics memory counter and be ready to start a bad line. Or, maybe
'NOT to go back to the current row' would be a more suitable
description. (Programming VIC-II is slowly becoming a science.)
The required timing also does not cause bad lines so that you can
skip another character row immediately on the successive line.
Because linecrunch causes VIC-II to skip rows, it will run out of
video matrix and color memory (and graphics memory) to show before
reaching the end of the screen. However, VIC-II does not stop
displaying the graphics nor does it reset the internal counters.
The counters keep on running and wrap around instead.
Normally, when VIC-II is displaying the last character row, it is
showing the memory from offsets $3c0 to $3e7. If VIC-II has skipped
one character row, it is displaying from $3e8 to $40f instead. But,
there are only 10 bits in the video matrix counter (locations
0..1023), so it wraps around to zero after $3ff. This means that
the beginning of the video matrix is displayed at the bottom of the
screen. The character rows become shifted by 24 character positions
to the right because there were originally 24 unused memory
locations at the end of the memory (1000..1023). (To be honest,
sprite image pointers are not unused memory, but they are not used
with normal FLI.)
____________________ ____________________
|abcdefghijklmnopqrst| |abcdefghijklmnopqrst|
| | |--------------------| <- Skipped row
: : : :
: : : :
: : : :
| | |normally last line |
|normally last line | |XXXXXXXXZZZZabcdefgh|
`--------------------' `--------------------'
X = unused mem (1000..1015)
Z = sprite pointers (1016..1023)
Figure 1: Linecrunch
The same thing happens for color memory because it uses the same
counter for addressing the memory (in fact, color memory access and
character data access are performed simultaneosly, 12 bits at a
time). The graphics memory behaves the same way, except that the
counter has three bits more and it counts at eight times the speed,
so that it wraps at the exact same time as the other counter.
_Back to BFLI_
Wrapped data is nothing difficult to work with. It is just the
matter of writing the right conversion program. (Which still may be
more than you can handle on the first attempt. I made several
attempts to get the file format right in the first place. And the
format has changed twice after that.) Also, the normal FLI routine
can be used, we only have to make sure VIC always has the right bank
visible - simple LDA bank,x:sta $DD00 can accomplish that.
The more difficult aspect is to make the display freely locatable.
We have 33 kilobytes of graphics data, this is the main reason we
can't even think about using copying. Linecrunch combined with the
bad line delaying technique will do the job much more nicely.
Figure 2 shows the principles. To make things simpler I have chosen
location 0 to mean that the top of the picture is visible, 1 means
that the picture is scrolled one line upwards and so on. We can see
that linecrunch is not used at all for the location 0. To make the
picture start at the same point whether linecrunch has crunched
lines or not we compensate the non-lost raster lines by delaying the
next bad line. When the location is n*8 (n=0,1,2..), the sum of the
linecrunched and delayed lines is constant - the graphics display
always starts at the same point.
Then how do we deal with the location values that are not evenly
dividable by eight ? Now, lets assume that the location is L, and
we have C, which is the location divided by eight (C = L/8), and R,
which is the remainder (R = L%8). To make the picture scroll to the
right position, we need to delay the bad line less than before - R
lines less for location L than for location C*8. E.g. for location
2 we delay the bad line two lines less than for location 0. This
also shows that we need 7 lines more than is needed for to
compensate for the linecrunch.
Determining the number of linecrunch lines is a recursive process,
because when you use more linecrunch lines, that decreases the
number of lines you have available for the display and you need
bigger range for the location value. We lose about two lines when
we use the soft y-scroll with the linecrunch and the 7 lines used in
the soft y-scroll itself. This makes 191 lines available for the
display originally.
Because we need to show 400 lines of graphics, we would need
(400-191)/8=27 linecrunch lines. However, this in turn reduces the
number of lines we have for graphics to 191-27=164 and we need
(400-164)/8=30 linecrunch lines. Again, 191-30 is 161. We get
(400-161)/8=30 and there it finally converges and we have 161 lines
for graphics, which makes location values 0..238 valid.
Location 0 1 2 .. 8 9 .. 238
___________________.. ___________.. ________
Linecrunch -------------------.. ___________..
^ ^ ^
| | | ^ ^
| | | | |
Bad line delayed| | | | |
| | | | | ========
| | v | | 232
| v ___.. | v :
v ________0 v ___.. :
Gfx Enabled ________0_______1__.. ________8__.. 237_____
0 1 2 8 9 238
1 2 3 9 10 239
2 3 4 10 11 240
3 4 5 11 12 241
4 5 6 12 13 242
5 6 7 13 14 243
6 7 8 14 15 244
7 8 9 15 16 245
: : : : : :
: : : : : :
160 161 162.. 168 169.. 399
Figure 2: Linecrunch and DMA delay in BFLI
(Graphics lines not in scale)
_Clipping added_
Now we can scroll the picture to any location we want, but the top
of the picture is not clipped and it is very annoying to watch.
(Change AND #$77 to AND #$37 inside LOOP 0 to see what I mean.)
We need to enable the graphics at the same point regardless of the
y-scroll value. The answer is in the extended color mode (ECM).
When both ECM and multicolor mode (MCM) are selected, VIC-II will
turn the display to black. This is because there is a conflicting
situation and it just can't decide which color scheme to use. The
video accesses will continue to happen just like before, the data is
just not displayed. When the ECM bit is cleared again, the normal
multicolor graphics is again shown.
So, we set the ECM bit and start to display the first eight lines of
the FLI. Because the FLI rout